package com.leetcode;

import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class LeetCode3 {

    public static void main(String[] args) {
        int length = lengthOfLongestSubstring("dvdf");
        System.out.println(length);
    }

    public static int lengthOfLongestSubstring(String s) {
        int length = 0;
        if("".equals(s)){
            return 0;
        }
        if("".equals(s.replaceAll(" ",""))){
            return 1;
        }
        char[] arry = s.toCharArray();
        Map<String,String> map = new HashMap<String,String>();
        for(char a : arry){
            String key = String.valueOf(a);
            if(!map.containsKey(key)){
                map.put(String.valueOf(key),key);
            }else{
                if(map.size() >= length)
                    length  = map.size();
                map = new HashMap<String,String>();
                map.put(String.valueOf(key),key);
            }
        }
        if(map.size() >= length)
            length  = map.size();
        return length;
    }



}